<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Token</title>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
</head>
<body>
<div style="width: 99%;margin:5px auto;">
<form class="col-xs-12">
	<div class="form-group">
	  <label for="username">username</label>
	  <input type="text" class="form-control" id="username" placeholder="username" value="admin">
	</div>
	<div class="form-group ">
	  <label for="password">Password</label>
	  <input type="text" class="form-control" id="password" placeholder="password" value="test01">
	</div>
	<button id="authorize" type="button" class="btn btn-primary">授权接口</button>
	
	
	<button id="refreshToken" type="button" class="btn btn-primary">刷新令牌接口</button>
</form>
</div>
<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function(){
	$('#authorize').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'json',
			data: {
				username: $('#username').val(), 
				password: $('#password').val()
			},
			url: 'http://test.iot.idao.me/token/authorize',
			success: function(rsp){
				if(rsp.success){
					localStorage.token = rsp.result.token
					alert(rsp.result.token)
				}else{
					alert(rsp.resultMsg)
				}
			}
		})
	});
	$('#refreshToken').bind('click', function(){
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: '../token/refreshToken',
			beforeSend: function (xhr) {
		        xhr.setRequestHeader("Authorization", localStorage.token);
		    },
			success: function(rsp){
				console.log(rsp)
			}
		})
	});
})
</script>
</body>
</html>